//
//  RenHouseDetailTopCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/19.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "RenHouseDetailTopCell.h"
#import <SDCycleScrollView/SDCycleScrollView.h>
#import "PictureBrowserVC.h"

#import "BaseNavigationController.h"

@interface RenHouseDetailTopCell ()<SDCycleScrollViewDelegate>
@property (nonatomic, weak) SDCycleScrollView *cycleView;
@property (weak, nonatomic) IBOutlet UILabel *topLabel;
@property (weak, nonatomic) IBOutlet UILabel *bottomRightLabel;

@property (weak, nonatomic) IBOutlet UILabel *bottomLeftLabel;
@property (weak, nonatomic) IBOutlet UILabel *middleOneLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewH;

@property (weak, nonatomic) IBOutlet UILabel *middleTwoLabel;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet UILabel *middleThreeLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;

@property (weak, nonatomic) IBOutlet UIImageView *addressImage;

@end

@implementation RenHouseDetailTopCell



- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.bgViewH.constant = KScreenW / 16.0 * 9;
    
    [self setupTopScrollview];
    
    
    self.topLabel.font = MYFONT(16);
    
    self.bottomLeftLabel.font = MYFONT(16);
    self.bottomLeftLabel.textColor = [UIColor orangeColor];
    
    self.bottomRightLabel.font = MYFONT(14);
    self.bottomRightLabel.textColor = darkGray;
    
    self.addressLabel.font = MYFONT(14);
    self.addressLabel.textColor = darkGray;
    self.addressLabel.text = @"";
    
    self.timeLabel.font = MYFONT(12);
    self.timeLabel.textColor = darkGray;
    
    self.middleOneLabel.font = MYFONT(12);
    self.middleTwoLabel.font = MYFONT(12);
    self.middleThreeLabel.font = MYFONT(12);
    self.middleThreeLabel.textColor = [UIColor orangeColor];
    self.middleTwoLabel.textColor = [UIColor orangeColor];
    self.middleOneLabel.textColor = [UIColor orangeColor];
    
    self.middleThreeLabel.layer.borderColor = [UIColor orangeColor].CGColor;
    self.middleThreeLabel.layer.borderWidth = 0.6;
    
    
    self.middleTwoLabel.layer.borderColor = [UIColor orangeColor].CGColor;
    self.middleTwoLabel.layer.borderWidth = 0.6;
    
    
    self.middleOneLabel.layer.borderColor = [UIColor orangeColor].CGColor;
    self.middleOneLabel.layer.borderWidth = 0.6;
    
//    self.middleTwoLabel.hidden = YES;
//
//    self.middleThreeLabel.hidden = YES;
    // Initialization code
}



- (void)setupTopScrollview{
    
    if (!_cycleView) {
        // 网络加载 --- 创建自定义图片的pageControlDot的图片轮播器
        SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, KScreenW, KScreenW / 16.0 * 9) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
        
        cycleScrollView.autoScrollTimeInterval = 3;
        cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        //    cycleScrollView3.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
        //    cycleScrollView3.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
        _cycleView = cycleScrollView;
        
//        _cycleView.imageURLStringsGroup = @[@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514278885&di=0a99bf1e62dedfae62c81a3668de6c41&imgtype=jpg&er=1&src=http%3A%2F%2Fstatic-zhuangxiu.17house.com%2Fweb%2Fzhuangxiu%2F201510%2F15%2F201510151022586009.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514278885&di=0a99bf1e62dedfae62c81a3668de6c41&imgtype=jpg&er=1&src=http%3A%2F%2Fstatic-zhuangxiu.17house.com%2Fweb%2Fzhuangxiu%2F201510%2F15%2F201510151022586009.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514278885&di=0a99bf1e62dedfae62c81a3668de6c41&imgtype=jpg&er=1&src=http%3A%2F%2Fstatic-zhuangxiu.17house.com%2Fweb%2Fzhuangxiu%2F201510%2F15%2F201510151022586009.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1514278885&di=0a99bf1e62dedfae62c81a3668de6c41&imgtype=jpg&er=1&src=http%3A%2F%2Fstatic-zhuangxiu.17house.com%2Fweb%2Fzhuangxiu%2F201510%2F15%2F201510151022586009.jpg"];

        [self.bgView addSubview:_cycleView];
        
        
    }
    
    
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    
    NSIndexPath *path = [NSIndexPath indexPathForItem:index inSection:0];
    
    NSMutableArray *arry = [NSMutableArray array];
    for (NSString *urlStr in self.model.house_pic) {
        [arry addObject:[NSURL URLWithString:urlStr]];
    }
   
    PictureBrowserVC *pictureVC = [PictureBrowserVC pictureBrowserControllerWith:path picURLs:arry];
    
    BaseNavigationController *nav = [[BaseNavigationController alloc]initWithRootViewController:pictureVC];
    
//    nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    
    [self.viewController presentViewController:nav animated:YES completion:nil];

    
}



- (void)setModel:(HouseDetailModel *)model{
    
    _model = model;
    
    self.bgViewH.constant = self.imgH;
    
    self.cycleView.height = self.imgH;
    
    self.cycleView.imageURLStringsGroup = _model.house_pic;
    
    
    if (_model.area.length > 0) {
        self.addressLabel.text = _model.area;
        self.addressImage.hidden = NO;
    }else{
        self.addressLabel.text = @"";
        self.addressImage.hidden = YES;

    }
    
    if (_model.house_language_names.count == 1) {
        
        self.middleOneLabel.hidden = NO;
        self.middleTwoLabel.hidden = YES;
        self.middleThreeLabel.hidden = YES;
        
        self.middleOneLabel.text =  [NSString stringWithFormat:@" %@ ",_model.house_language_names.firstObject];
        
        
    } else if (_model.house_language_names.count == 2){
        
        self.middleOneLabel.hidden = NO;
        self.middleTwoLabel.hidden = NO;
        self.middleThreeLabel.hidden = YES;
        self.middleOneLabel.text =  [NSString stringWithFormat:@" %@ ",_model.house_language_names.firstObject];
        
        self.middleTwoLabel.text =  [NSString stringWithFormat:@" %@ ",_model.house_language_names.lastObject];
        
    }else{
        
        self.middleOneLabel.hidden = NO;
        self.middleTwoLabel.hidden = NO;
        self.middleThreeLabel.hidden = NO;
        
        self.middleOneLabel.text =  [NSString stringWithFormat:@" %@ ",_model.house_language_names.firstObject];
        
        self.middleTwoLabel.text =  [NSString stringWithFormat:@" %@ ",_model.house_language_names[1]];
        
        
        self.middleThreeLabel.text =  [NSString stringWithFormat:@" %@ ",_model.house_language_names.lastObject];
        
    }
    
    
    self.timeLabel.text = [NSString stringWithFormat:@"发布于%@",_model.house_createtime];
    
    
    self.bottomLeftLabel.text = [NSString stringWithFormat:@"%@/月",_model.house_price];
    
    
    
    for (HouseParameSub *sub in myViewModel.parameterModel.fukuan) {
        
        if ([sub.class_id isEqualToString:_model.pay_class_id]) {
            
            self.bottomRightLabel.text = sub.name;
            
        }
    }
    
    self.topLabel.text = _model.house_title;
    
    
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    

}

@end
